#ifndef LEAF_H
#define LEAF_H

#include "BufferFrame.h"
#include "Node.h"

struct leafBla
{
    NodeHeader header;
    long key0;
    unsigned child1;
    long key1;
    unsigned child2;
    long key2;
    unsigned child3;
    long key3;
    unsigned child4;
    long key4;
    unsigned child5;
};

class Leaf
{
private:
    Leaf(BufferFrame& page, NodeContext& nodeContext);
    BufferFrame& page;
    NodeHeader& header;
    NodeContext& context;

	unsigned getMaxEntryCount();
	void insertToRightPosition(char* key, TID tid, char* dataStart, unsigned dataCount);

public:
    static Leaf fromNew(BufferFrame& page, NodeContext& nodeContext);
    static Leaf fromExisting(BufferFrame& page, NodeContext& nodeContext);

    SplitOp insert(char* key, TID tid);
    RemovalResult* remove(char* key, bool isRoot);
    TID lookup(char* key);
    index_iterator lookupRange(char* key1, char* key2);
    void visualize(IndexVisualizer& vis, unsigned pageId);
};

#endif // LEAF_H_INCLUDED
